<template>
  <div class="login-page">
    <!-- 背景装饰 -->
    <div class="login-bg"></div>
    
    <!-- 注册卡片 -->
    <div class="login-card">
      <div class="login-header">
        <h1 class="login-title">找回密码</h1>
      </div>
      
      <!-- 注册表单 -->
      <el-form 
        ref="loginFormRef" 
        :model="loginForm" 
        :rules="loginRules" 
        class="login-form"
        label-position="top"
      >
        <el-form-item label="手机号" prop="phone">
          <el-input 
            v-model="loginForm.phone" 
            placeholder="请输入手机号" 
            :prefix-icon="Phone"
            autocomplete="off"
            size="large"
          />
        </el-form-item>

        <el-form-item label="手机验证码" prop="phoneCode">
          <el-input 
            v-model="loginForm.phoneCode" 
            placeholder="请输入手机号" 
            :prefix-icon="Phone"
            autocomplete="off"
            size="large"
          />
        </el-form-item>
        
        <el-form-item label="新密码" prop="password">
          <el-input 
            v-model="loginForm.password" 
            type="password" 
            placeholder="请输入密码" 
            :prefix-icon="Lock"
            show-password
            autocomplete="off"
            size="large"
          />
        </el-form-item>

        <el-form-item label="确认密码" prop="passwordConfirm">
          <el-input 
            v-model="loginForm.passwordConfirm" 
            type="password" 
            placeholder="请确认您输入密码" 
            :prefix-icon="Lock"
            show-password
            autocomplete="off"
            size="large"
          />
        </el-form-item>

        <el-form-item>
          <el-button 
            type="primary" 
            class="login-button" 
            :loading="loading"
            size="large"
          >
            修改密码
          </el-button>
        </el-form-item>
      </el-form>

      <div class="decoration decoration-1"></div>
      <div class="decoration decoration-2"></div>
      <div class="decoration decoration-3"></div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'
import { ElForm, type FormRules } from 'element-plus'
import { useHead, useRouter } from 'nuxt/app'

import { Phone, Lock } from '@element-plus/icons-vue'

// 禁用页面布局
useHead({
  title: "找回密码 - 水晶战争游戏平台",
})

const router = useRouter()

// 表单引用
const loginFormRef = ref<InstanceType<typeof ElForm>>()

// 加载状态
const loading = ref(false)

// 登录表单数据
const loginForm = reactive({
  phone: '',
  phoneCode: '',
  username: '',
  password: '',
  passwordConfirm: '',
})

// 表单验证规则
const loginRules = reactive<FormRules>({
  phone: [
    { required: true, message: '请输入手机号', trigger: 'blur' },
    { pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号', trigger: 'blur' }
  ],
  phoneCode: [
    { required: true, message: '请输入手机验证码', trigger: 'blur' },
    { pattern: /^\d{6}$/, message: '验证码必须为6位数字', trigger: 'blur' }
  ],
  username: [
    { required: true, message: '请输入用户名', trigger: 'blur' },
    { min: 3, max: 20, message: '用户名长度在 3 到 20 个字符', trigger: 'blur' },
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    { min: 6, max: 30, message: '密码长度在 6 到 30 个字符', trigger: 'blur' }
  ],
  passwordConfirm: [
    { required: true, message: '请确认密码', trigger: 'blur' },
    { validator: (rule, value, callback) => {
        if (value !== loginForm.password) {
          callback(new Error('两次输入的密码不一致'))
        } else {
          callback()
        }
      }, trigger: 'blur' }
  ]


})


</script>

<style scoped>
.login-page {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  padding: 20px;
}

.login-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #43cea2 0%, #185a9d 100%);
  z-index: -1;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  padding: 40px 30px;
  animation: fadeIn 0.6s ease-out;
}

.login-header {
  text-align: center;
  margin-bottom: 30px;
}

.login-title {
  color: #1f2329;
  font-size: 28px;
  margin: 0 0 10px 0;
  font-weight: 600;
}

.login-desc {
  color: #666;
  font-size: 14px;
  margin: 0;
}

.login-form {
  width: 100%;
}

.form-actions {
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 14px;
  color: #409eff;
}

.login-button {
  width: 100%;
  padding: 12px 0;
  font-size: 16px;
  transition: all 0.3s ease;
  margin-bottom: 0;
  margin-top: 20px;
  
}

.login-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(64, 158, 255, 0.35);
}

.register-link {
  text-align: center;
  margin-top: 25px;
  color: #666;
  font-size: 14px;
}

.form-links {
  color: #409eff;
  cursor: pointer;
  text-decoration: none;
  transition: color 0.3s ease;
  margin-left: 50px;
  margin-right: 50px;
}

/* 装饰元素 */
.decoration {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  animation: float 6s ease-in-out infinite;
}

.decoration-1 {
  width: 80px;
  height: 80px;
  top: 20%;
  left: 10%;
  animation-delay: 0s;
}

.decoration-2 {
  width: 120px;
  height: 120px;
  bottom: 15%;
  right: 15%;
  animation-delay: 2s;
}

.decoration-3 {
  width: 60px;
  height: 60px;
  top: 60%;
  left: 20%;
  animation-delay: 4s;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px) rotate(0deg);
  }
  50% {
    transform: translateY(-20px) rotate(180deg);
  }
}

/* 动画效果 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 响应式调整 */
@media (max-width: 576px) {
  .login-card {
    padding: 30px 20px;
  }
  
  .login-title {
    font-size: 24px;
  }
}
</style>
